package com.lzc.tlmail.cart.tlmailcart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车vo
 * @author lzc
 * @create 2020-10-18 14:26
 */
public class CartVo {

    /**
     * 所有购物车项
     */
    private List<CartItemVo> cartItemVoList;

    /**
     * 商品类别数量
     */
    private Integer countType;
    /**
     * 商品总数
     */
    private Integer countItem;
    /**
     * 总价
     */
    private BigDecimal totalPrice;

    /**
     * 促销
     */
    private BigDecimal promotion=new BigDecimal("0.00");


    public List<CartItemVo> getCartItemVoList() {
        return cartItemVoList;
    }

    public void setCartItemVoList(List<CartItemVo> cartItemVoList) {
        this.cartItemVoList = cartItemVoList;
    }

    public Integer getCountType() {
        int count=0;
        if(cartItemVoList!=null&&cartItemVoList.size()>0){
            for (CartItemVo cartItemVo : cartItemVoList) {
                count+=1;
            }
        }
        return count;
    }



    public Integer getCountItem() {
        int count=0;
        if(cartItemVoList!=null&&cartItemVoList.size()>0){
            for (CartItemVo cartItemVo : cartItemVoList) {
                if(cartItemVo.getChecked()){
                    count+=cartItemVo.getCount();
                }
            }
        }
        return count;
    }


    public BigDecimal getTotalPrice() {
        BigDecimal toPrice = new BigDecimal("0");
        if(cartItemVoList!=null&&cartItemVoList.size()>0){
            for (CartItemVo cartItemVo : cartItemVoList) {
                if(cartItemVo.getChecked()){
                    toPrice=toPrice.add(cartItemVo.getTotalPrice());
                }
            }
        }

        if(this.getPromotion()!=null){
            toPrice= toPrice.subtract(this.getPromotion());
        }
        return toPrice;
    }



    public BigDecimal getPromotion() {
        return promotion;
    }

    public void setPromotion(BigDecimal promotion) {
        this.promotion = promotion;
    }
}
